﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using UniversityManagementSystem.DAL;

namespace UniversityManagementSystem.Gateway
{
    [Serializable]
    public class SemesterGateway : GatewayConnection
    {
        private string commandString = null;
        [NonSerialized]
        private SqlDataReader getData = null;
        public List<Semester> GetAllSemesters()
        {
            List<Semester> allSemesters = new List<Semester>();
            try
            {
                GetSqlConn.Open();
                commandString = string.Format("SELECT * FROM t_Semester");
                GetSqlCommand.CommandText = commandString;
                getData = GetSqlCommand.ExecuteReader();
                while (getData.Read())
                {
                    Semester aSemester = new Semester();
                    aSemester.SemesterId = Convert.ToInt32(getData["semester_code"]);
                    aSemester.SemesterName = getData["semester_name"].ToString();
                    allSemesters.Add(aSemester);
                }
                GetSqlConn.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if ((GetSqlConn != null) && (GetSqlConn.State == ConnectionState.Open))
                    GetSqlConn.Close();
            }
            return allSemesters;
        }
    }
}